package com.ruoyi.channel.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.channel.domain.ChannelMerchants;
import com.ruoyi.channel.service.IChannelMerchantsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 渠道商数据Controller
 *
 * @author ruoyi
 * @date 2025-04-09
 */
@RestController
@RequestMapping("/channelMerchants/channelMerchants")
public class ChannelMerchantsController extends BaseController {
    @Autowired
    private IChannelMerchantsService channelMerchantsService;

    /**
     * 查询渠道商数据列表
     */
    @PreAuthorize("@ss.hasPermi('channelMerchants:channelMerchants:list')")
    @GetMapping("/list")
    public TableDataInfo list(ChannelMerchants channelMerchants) {
        startPage();
        List<ChannelMerchants> list = channelMerchantsService.selectChannelMerchantsList(channelMerchants);
        return getDataTable(list);
    }

    /**
     * 导出渠道商数据列表
     */
    @PreAuthorize("@ss.hasPermi('channelMerchants:channelMerchants:export')")
    @Log(title = "渠道商数据", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ChannelMerchants channelMerchants) {
        List<ChannelMerchants> list = channelMerchantsService.selectChannelMerchantsList(channelMerchants);
        ExcelUtil<ChannelMerchants> util = new ExcelUtil<ChannelMerchants>(ChannelMerchants.class);
        util.exportExcel(response, list, "渠道商数据数据");
    }

    /**
     * 获取渠道商数据详细信息
     */
    @PreAuthorize("@ss.hasPermi('channelMerchants:channelMerchants:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(channelMerchantsService.selectChannelMerchantsById(id));
    }

    /**
     * 新增渠道商数据
     */
    @PreAuthorize("@ss.hasPermi('channelMerchants:channelMerchants:add')")
    @Log(title = "渠道商数据", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ChannelMerchants channelMerchants) {
        return toAjax(channelMerchantsService.insertChannelMerchants(channelMerchants));
    }

    /**
     * 修改渠道商数据
     */
    @PreAuthorize("@ss.hasPermi('channelMerchants:channelMerchants:edit')")
    @Log(title = "渠道商数据", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ChannelMerchants channelMerchants) {
        return toAjax(channelMerchantsService.updateChannelMerchants(channelMerchants));
    }

    /**
     * 删除渠道商数据
     */
    @PreAuthorize("@ss.hasPermi('channelMerchants:channelMerchants:remove')")
    @Log(title = "渠道商数据", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(channelMerchantsService.deleteChannelMerchantsByIds(ids));
    }
}
